<?php
/**
 * Created by PhpStorm.
 * User: 13790
 * Date: 2018/3/21
 * Time: 23:08
 */


namespace app\admin\controller;


use think\Controller;

class Base extends Controller
{

    protected function _initialize()
    {
        $admin_user = session('admin_user');
        $admin_id = session('admin_id');

        if (!$admin_user) {
            return $this->success('请先登录', 'Login/login');
        }
        /*****判断是否具有权限******/

        $m = request()->module();     //获取当前模块
        $c = request()->controller(); //当前控制器
        $f = request()->action(); //当前方法

        if($admin_user != 'admin'){
            $data = db('role_auth')
                ->field('b.auth_name')
                ->alias('a')
                ->join('auth b','a.auth_id = b.id','LEFT')
                ->join('admin_role c','a.role_id = c.role_id','LEFT')
                ->where('admin_id','=',$admin_id)
                ->where('b.auth_m',$m)
                ->where('b.auth_c',$c)
                ->where('b.auth_f',$f)
                ->find();
            if(!$data){
                if(input('param.flag' == 'pic')){
                    echo json_encode([
                        'status' =>  2,
                        'msg'   =>  '无权访问'
                    ]);
                    exit;
                }
                return $this->error('无权访问');
            }

        }
    }
}